//
//  TXFStatuesTwoView.swift
//  weibo飞飞
//
//  Created by 田侠飞 on 16/6/29.
//  Copyright © 2016年 田侠飞. All rights reserved.
//

import UIKit

class TXFStatuesTwoView: UIView {
    var retwetButton : UIButton?
    var commentButton : UIButton?
    var unlikeButton : UIButton?
 
    //设置评论数:
 
    var status : TXFStatues? {
        
        didSet{
            
            //可以复制
         retwetButton?.setTitle(status?.repostsStr, forState: UIControlState.Normal)
         commentButton?.setTitle(status?.commentsStr, forState: UIControlState.Normal)
         unlikeButton?.setTitle(status?.attitudesStr, forState: UIControlState.Normal)
            
            commentButton?.addTarget(self, action: "BtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        }
        
        
    }
    
    
    //评论内容:
    func BtnClick(){
        
        print("111")
        
        //获取数据:
        let  comment = "呵呵呵"
 
        TXFNetworkTools.shareTools.sendWBCommentsData(comment, success: { (response) -> () in
            
            print(response)
            
            }) { (error) -> () in
              print(error)
        }
 
        
        
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        //创建控件:
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func  setupUI(){
    
    retwetButton = addChildButtons(UIImage(named: "timeline_icon_retweet")!, title: "转发")
    
    commentButton = addChildButtons(UIImage(named: "timeline_icon_comment")!, title: "评论")
    
    unlikeButton = addChildButtons(UIImage(named: "timeline_icon_unlike")!, title: "赞")
        
        
        
      
        
    let line1 = addChildLines()
    let line2 = addChildLines()
        //设置约束:
        
        
        retwetButton?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.top.left.bottom.equalTo(self)
            
            make.width.equalTo(commentButton!)
            
        })
        commentButton?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.top.bottom.equalTo(self)
            make.left.equalTo(retwetButton!.snp_right)
            make.width.equalTo(unlikeButton!)
            
        })
        unlikeButton?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.top.bottom.trailing.equalTo(self)
            make.left.equalTo(commentButton!.snp_right)
            
            
        })
        line1.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(self)
            
            make.centerX.equalTo(retwetButton!.snp_right)
            
        }
        line2.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(self)
            
            make.centerX.equalTo(commentButton!.snp_right)
            
            
        }
        
      
      
        
        
    }
    
   
    func addChildButtons(image: UIImage, title: String)->UIButton{
    
    let button = UIButton()
        button.setTitle(title, forState: UIControlState.Normal)
        button.setImage(image, forState: UIControlState.Normal)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        
         button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
         button.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        
         button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        
        addSubview(button)
    
    
    return button
    }
    //添加了两条线的控件:
    
    private func addChildLines() -> UIImageView{
    
    let img = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
    
    
    addSubview(img)
        
        return img
    }
    
    
}
